package com.example.child_protection.controller;

import com.example.child_protection.dto.base.BaseResponseDTO;
import com.example.child_protection.dto.request.SimpleIdRequestDTO;
import com.example.child_protection.dto.request.add.SystemVaccineInsertRequestDTO;
import com.example.child_protection.dto.request.find.SystemVaccineRequestDTO;
import com.example.child_protection.dto.request.update.SystemVaccineUpdateRequestDTO;
import com.example.child_protection.dto.response.SystemVaccineListResponseDTO;
import com.example.child_protection.dto.response.SystemVaccineResponseDTO;
import com.example.child_protection.service.SystemVaccineManageService;
import com.example.child_protection.service.SystemVaccineQueryService;
import com.example.child_protection.util.ContentType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * 疫苗管理控制层
 * @date 2018-11-2
 * @author Biz
 */
@RestController
@RequestMapping("systemVaccine")
@Api(value = "/api-systemVaccine", description = "疫苗管理")
public class SystemVaccineController extends BaseController {

    @Autowired
    public SystemVaccineManageService systemVaccineManageService;

    @Autowired
    public SystemVaccineQueryService systemVaccineQueryService;

    @ApiOperation(value ="查询疫苗", httpMethod = "POST",response = BaseResponseDTO.class )
    @RequestMapping(value = "/findId", method = RequestMethod.POST, produces = {ContentType.APPLICATION_JSON_UTF_8, ContentType.TEXT_XML_UTF_8})
    public SystemVaccineResponseDTO findId(SimpleIdRequestDTO requestDTO,HttpServletRequest request)throws Exception{
        logger.info("用户ID{},sessionId{}",request.getSession().getAttribute("user"),request.getSession().getId());
        SystemVaccineResponseDTO responseDTO = systemVaccineQueryService.findId(requestDTO);
        return responseDTO;
    }

    @ApiOperation(value ="查询疫苗列表信息", httpMethod = "POST",response = BaseResponseDTO.class )
    @RequestMapping(value = "/findList", method = RequestMethod.POST, produces = {ContentType.APPLICATION_JSON_UTF_8, ContentType.TEXT_XML_UTF_8})
    public SystemVaccineListResponseDTO findList(SystemVaccineRequestDTO requestDTO, HttpServletRequest request)throws Exception{
        SystemVaccineListResponseDTO responseDTO = systemVaccineQueryService.findList(requestDTO);
        return responseDTO;
    }

    @ApiOperation(value ="添加疫苗", httpMethod = "POST",response = BaseResponseDTO.class )
    @RequestMapping(value = "/insert", method = RequestMethod.POST, produces = {ContentType.APPLICATION_JSON_UTF_8, ContentType.TEXT_XML_UTF_8})
    public BaseResponseDTO insert(SystemVaccineInsertRequestDTO requestDTO)throws Exception{
        requestDTO.setCreatePersonId(this.getLoginUserId());
        requestDTO.setLastUpdatePersonId(this.getLoginUserId());
        BaseResponseDTO responseDTO = systemVaccineManageService.insert(requestDTO);
        return responseDTO;
    }

    @ApiOperation(value ="修改疫苗", httpMethod = "POST",response = BaseResponseDTO.class )
    @RequestMapping(value = "/update", method = RequestMethod.POST, produces = {ContentType.APPLICATION_JSON_UTF_8, ContentType.TEXT_XML_UTF_8})
    public BaseResponseDTO update(SystemVaccineUpdateRequestDTO requestDTO)throws Exception{
        requestDTO.setLastUpdatePersonId(this.getLoginUserId());
        BaseResponseDTO responseDTO = systemVaccineManageService.update(requestDTO);
        return responseDTO;
    }

    @ApiOperation(value ="删除疫苗", httpMethod = "POST",response = BaseResponseDTO.class )
    @RequestMapping(value = "/delete", method = RequestMethod.POST, produces = {ContentType.APPLICATION_JSON_UTF_8, ContentType.TEXT_XML_UTF_8})
    public BaseResponseDTO delete(SimpleIdRequestDTO requestDTO)throws Exception{
        requestDTO.setLastUpdatePersonId(this.getLoginUserId());
        BaseResponseDTO responseDTO = systemVaccineManageService.delete(requestDTO);
        return responseDTO;
    }

}
